﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using Generico.Coneccion;
using System.Data;

namespace RosarioFinanzas
{
    public partial class default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [WebMethod]
        public static string strFecha(string str)
        {

            string[] dayarray = { "Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado" };
            string[] montharray = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" };
            var daym = DateTime.Today.Day.ToString();
            var year = DateTime.Today.Year.ToString();
            var day = Convert.ToInt32(DateTime.Today.DayOfWeek);
            var month = DateTime.Today.Month - 1;
            return dayarray[day] + ", " + daym + " de " + montharray[month] + " del " + year + " ";

        }

        [WebMethod]
        public static string ObtenerCotizacionesMonedas(string str)
        {
            var cn = new ClsConeccion();
            
            //     Monedas

            cn.Abrir();
            string sql = "Select varMoneda, '$' + Replace (Cast(Cast(PromedioRFCompra as Numeric(9,3)) as varchar),'.',',')  Compra, '$' + Replace (Cast(Cast(PromedioRFVenta as Numeric(9,3)) as varchar),'.',',')  Venta From Promedios P ";
            sql += "inner Join  (Select Moneda, Max(Fecha) fec From Promedios ";
            sql += "group by Moneda) P1 on P1.Moneda = P.Moneda and P1.Fec = P.Fecha ";
            sql += "Inner Join Monedas M on P.Moneda = M.idMoneda order by P.Moneda ";
            var sqldr2 = cn.EjecutarSqlDataReader(sql);
            var dt = new DataTable();
            dt.Load(sqldr2);
            cn.Cerrar();

            string html = "<div><ul id=\"marquesinaMonedas\">";

            foreach (DataRow dr in dt.Rows)
            {

                switch (dr["varMoneda"].ToString())
                {
                    case "DÓLAR":
                        html += "<li ><a href=\"Mercados/Bursatil.aspx\" style=\"text-decoration: none;\"><img src=\"imagenes/Monedas/us_flag.png\" style=\"height:16px; margin-left:20px;\"></li><li> Dólar </li>";
                        break;

                    case "EURO":
                        html += "<li ><a href=\"Mercados/Bursatil.aspx\" style=\"text-decoration: none;\" ><img src=\"imagenes/Monedas/european_flag.png\" style=\"height:16px; margin-left:20px;\"></li><li> Euro </li>";
                        break;

                    case "REAL":
                        html += "<li ><a href=\"Mercados/Bursatil.aspx\" style=\"text-decoration: none;\" ><img src=\"imagenes/Monedas/brazil_flag.jpg\" style=\"height:16px; margin-left:20px;\"></li><li> Real </li>";
                        break;

                    default:
                        break;
                }


                html += "<li style=\" color: #33b165;\"> " + dr["Compra"].ToString() + " </li><li> / </li>";
                html += "<li style=\" color: #d64837;\"> " + dr["Venta"].ToString() + " </a></li>";

            }            


            // Pizarra BCR
            
            cn.Abrir();
            string sql_bcr = "SELECT varDescripcion , '$' + Replace (Cast(Cast(MontoHoy as Numeric(9,2)) as varchar),'.',',') Monto ";
                   sql_bcr += "FROM dbo.BCRCotizacion BCR ";
                   sql_bcr += "INNER JOIN (SELECT intIdIndice, max(Fecha) Fecha FROM BCRCotizacion ";
                   sql_bcr += "GROUP BY intIdIndice) AS B ON BCR.intIdIndice = B.intIdIndice AND BCR.Fecha = B.Fecha ";
                   sql_bcr += "INNER JOIN dbo.Indice I ON I.intIndice = BCR.intIdIndice ";

            var sqldr_bcr = cn.EjecutarSqlDataReader(sql_bcr);
            var dt_bcr = new DataTable();
            dt_bcr.Load(sqldr_bcr);
            cn.Cerrar();

            foreach (DataRow dr_bcr in dt_bcr.Rows)
            {

                switch (dr_bcr["varDescripcion"].ToString())
                {

                    case "Maiz Duro":
                        html += "<li ><img src=\"imagenes/Agro/corn_icon.png\" style=\"height:16px; margin-left:20px;\"></li><li> Maiz Duro </li>";
                        break;

                    case "Soja":
                        html += "<li ><img src=\"imagenes/Agro/soybean_icon.png\" style=\"height:16px; margin-left:20px;\"></li><li> Soja </li>";
                        break;

                    case "Trigo":
                        html += "<li ><img src=\"imagenes/Agro/wheat_icon.png\" style=\"height:16px; margin-left:20px;\"></li><li> Trigo </li>";
                        break;

                    case "Girasol":
                        html += "<li ><img src=\"imagenes/Agro/sunflower_icon.png\" style=\"height:16px; margin-left:20px;\"></li><li> Girasol </li>";
                        break;

                    case "Sorgo":
                        html += "<li ><img src=\"imagenes/Agro/sorghum_icon.png\" style=\"height:16px; margin-left:20px;\"></li><li> Sorgo </li>";
                        break;

                    default:
                        break;
                }

                if (dr_bcr["Monto"].ToString() == "$0,00")
                    html += "<li style=\" color: #2012E1;\"> S/C </li>";              
                else
                    html += "<li style=\" color: #2012E1;\"> " + dr_bcr["Monto"].ToString() + " </li>";  
            }

            html += "</ul></div>";
            return html;
        }
    }
}
